package com.css.apps.task.admin.action;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.css.apps.task.job.JobManager;
import com.css.apps.task.model.TTask;
import com.css.apps.task.obj.TTaskItem;
import com.css.core.configuration.Environment;
import com.css.util.Ajax;
import com.css.util.Messages;
import com.css.util.StringHelper;
import com.css.webbase.webwork.action.AdminAction;
import com.opensymphony.xwork.Action;

@SuppressWarnings("serial")
public class ExecTimerTask extends AdminAction {

	private static Log log = LogFactory.getLog(ExecTimerTask.class);
	private String uuid;

	public String adminGo() {
		try {
			if (StringHelper.isEmpty(uuid)) {
				result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.fieldEmpty"));
				return Action.ERROR;
			}
			TTask item = TTaskItem.getTask(uuid);
			if (item == null) {
				result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.recordnotfound"));
				return Action.ERROR;
			}
			// if(DoJob.visitUrl(item, JobTemplate.EXEC_MANUAL) !=
			// HttpStatus.SC_OK){
			// result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS,
			// Messages.getString("systemMsg.urlNotExist"));
			// return Action.SUCCESS;
			// }
			JobManager.execute(item);
			result = Ajax.JSONResult(Environment.RESULT_CODE_SUCCESS, Messages.getString("systemMsg.success"));
			return Action.SUCCESS;
		} catch (Exception ex) {
			result = Ajax.JSONResult(Environment.RESULT_CODE_ERROR, Messages.getString("systemMsg.exception"));
			log.error(ex.getMessage(), ex);
			return Action.ERROR;
		}
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

}
